home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 October / EnigmA AMIGA RUN 22 (1997)(G.R. Edizioni)(IT)[!][issue 1997-10 & 11][EAR-CD VI].iso / progs / devel / pcq12d_2 / examples / showva.p < prev    next >
Text File  |  1991-09-06  |  1KB  |  60 lines

  1. Program ShowVA;
  2.  
  3. {
  4.     This program is a simple example of using a variable
  5.     number of parameters along with the va_start and va_arg
  6.     routines.
  7. }
  8.  
  9.  
  10. { If we want to use unnamed arguments, we'll need to use the    }
  11. { C interface.  Thus the following directive:            }
  12. {$C+}
  13.  
  14.  
  15. {   The WriteAll routine requires at least one argument, an    }
  16. {   Integer that tells us how many arguments have been passed.    }
  17. {   This integer can be from 0 to any number.            }
  18.  
  19.  
  20. Procedure WriteAll(Number : Integer; ... );
  21. var
  22.     AP : Address;  { This will be our Argument Pointer variable }
  23.     i  : Integer;
  24. begin
  25.     va_start(AP);  { Initialize AP }
  26.  
  27.     { va_arg will return the current item, and advance AP    }
  28.  
  29.     for i := 1 to Number do
  30.     Writeln(va_arg(AP,Integer));
  31. end;
  32.  
  33.  
  34. {  This routine shows that you don't have to use integers - you    }
  35. {  can use any simple type.                    }
  36.  
  37. Procedure WriteChars(Number : Integer ... );
  38. var
  39.     AP : Address;
  40.     i  : Integer;
  41. begin
  42.     va_start(AP);
  43.     for i := 1 to Number do
  44.     Writeln(va_arg(AP,Char));
  45. end;
  46.  
  47. begin
  48.     WriteAll(0);            { Writes nothing }
  49.     WriteAll(0,1,2,3,4,5,6,7,8,9);    { Also writes nothing }
  50.     WriteAll(4,100000,100001,100002,100003);
  51.     WriteAll(1,MaxInt);
  52.  
  53.     { Note that we can mix types, as in this case, but the    }
  54.     { compiler will not complain.  Therefore you need to be    }
  55.     { very careful.                        }
  56.  
  57.     WriteChars(4,'A','B',67,'D');
  58. end.
  59.  
  60.